#include "Hmi/wyzkr688rfswhmi.h"
#include "ui_robotview.h"
#include "ui_remoterobotview.h"
#include "Package/QCustomplot/qcustomplot.h"
#include "Package/RobotOpenGLView/RoboticOpenGLView.h"
#include "Hmi/RSFWTooLPin/RSFWTooLPinOpenGLView.h"

wyzkr688rfswhmi::wyzkr688rfswhmi(short Local_Remote){
    LocalRemote = Local_Remote;
    if(LocalRemote == LOCALCONTOLLER){
        this->ui = new Ui::RFSWView;
        this->ui->setupUi(this);
        this->UiDataInit();
        this->RobotScopeInit();
        this->ForceScopeInit();
        this->SignalSlotConnect();
    }
    else{
        this->remoteui = new Ui::RemoteRFSWView;
        this->remoteui->setupUi(this);
        this->UiDataInit();
        this->RobotScopeInit();
        this->ForceScopeInit();
        this->SignalSlotConnect();
    }

}

wyzkr688rfswhmi::~wyzkr688rfswhmi(){
    if(LocalRemote == LOCALCONTOLLER){
        this->UiDataRelease();
        this->ForceScopeRelease();
        this->RobotScopeRelease();
    }
    else{
        this->UiDataRelease();
        this->ForceScopeRelease();
        this->RobotScopeRelease();
    }
}

short wyzkr688rfswhmi::getBackendhandle(BackendInterface* p){
    if(LocalRemote == LOCALCONTOLLER){
        this->pbackendinterface = p;
        return 1;
    }
    else{
        return 0;
    }
}
short  wyzkr688rfswhmi::SignalSlotConnect(){
    if(LocalRemote == LOCALCONTOLLER){
    }
    else{
    }
    return 1;
}

short wyzkr688rfswhmi::UiDataInit(){
    if(LocalRemote == LOCALCONTOLLER){

    }
    else{

    }
    return 1;
}

short wyzkr688rfswhmi::UiDataUpdate(){
    if(this->LocalRemote == LOCALCONTOLLER){
        if(this->pbackendinterface != nullptr){
            this->pbackendinterface->ReadSpindleSpeed(mTechData.SpindleSpeedReal);
            this->pbackendinterface->ReadForceControlInitForceSetValue(mTechData.ForceInitPosSet);
            this->pbackendinterface->ReadInitPosDelayTime(mTechData.InitPosDelayTime);
            this->pbackendinterface->ReadForceControlForceSetValue(mTechData.ForceProcessSet);
            this->pbackendinterface->ReadForceControlStep(mTechData.ForceAdjGlobalCoefficient);
            this->pbackendinterface->ReadRFSWStage(mTechData.RFSWStage);
        }
        ui->SpindleInfo->setNum(mTechData.SpindleSpeedReal);
        ui->InitForceInfo->setNum(mTechData.ForceInitPosSet);
        ui->InitDelayInfo->setNum(mTechData.InitPosDelayTime);
        ui->ForceInfo->setNum(mTechData.ForceProcessSet);
        ui->ForceCoefficientInfo->setNum(mTechData.ForceAdjGlobalCoefficient);

        switch (mTechData.RFSWStage) {
        case 0:
            ui->UnWedlingStage->setStyleSheet("color:#2D3E50;background:#B8C6D1;");
            ui->InsertStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            ui->PreStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            ui->WeldingStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            ui->FinishStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            break;
        case 1:
            ui->UnWedlingStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            ui->InsertStage->setStyleSheet("color:#2D3E50;background:#B8C6D1;");
            ui->PreStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            ui->WeldingStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            ui->FinishStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            break;
        case 2:
            ui->UnWedlingStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            ui->InsertStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            ui->PreStage->setStyleSheet("color:#2D3E50;background:#B8C6D1;");
            ui->WeldingStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            ui->FinishStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            break;
        case 3:
            ui->UnWedlingStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            ui->InsertStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            ui->PreStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            ui->WeldingStage->setStyleSheet("color:#2D3E50;background:#B8C6D1;");
            ui->FinishStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            break;
        case 4:
            ui->UnWedlingStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            ui->InsertStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            ui->PreStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            ui->WeldingStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            ui->FinishStage->setStyleSheet("color:#2D3E50;background:#B8C6D1;");
            break;
        default:
            break;
        }
    }
    else{
        remoteui->SpindleInfo->setNum(mTechData.SpindleSpeedReal);
        remoteui->InitForceInfo->setNum(mTechData.ForceInitPosSet);
        remoteui->InitDelayInfo->setNum(mTechData.InitPosDelayTime);
        remoteui->ForceInfo->setNum(mTechData.ForceProcessSet);
        remoteui->ForceCoefficientInfo->setNum(mTechData.ForceAdjGlobalCoefficient);

        switch (mTechData.RFSWStage) {
        case 0:
            remoteui->UnWedlingStage->setStyleSheet("color:#2D3E50;background:#B8C6D1;");
            remoteui->InsertStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            remoteui->PreStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            remoteui->WeldingStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            remoteui->FinishStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            break;
        case 1:
            remoteui->UnWedlingStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            remoteui->InsertStage->setStyleSheet("color:#2D3E50;background:#B8C6D1;");
            remoteui->PreStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            remoteui->WeldingStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            remoteui->FinishStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            break;
        case 2:
            remoteui->UnWedlingStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            remoteui->InsertStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            remoteui->PreStage->setStyleSheet("color:#2D3E50;background:#B8C6D1;");
            remoteui->WeldingStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            remoteui->FinishStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            break;
        case 3:
            remoteui->UnWedlingStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            remoteui->InsertStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            remoteui->PreStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            remoteui->WeldingStage->setStyleSheet("color:#2D3E50;background:#B8C6D1;");
            remoteui->FinishStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            break;
        case 4:
            remoteui->UnWedlingStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            remoteui->InsertStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            remoteui->PreStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            remoteui->WeldingStage->setStyleSheet("color:#34495E; background:#E7E7E7;");
            remoteui->FinishStage->setStyleSheet("color:#2D3E50;background:#B8C6D1;");
            break;
        default:
            break;
        }
    }
    return 1;
}

short wyzkr688rfswhmi::UiDataRelease(){
    if(LocalRemote == LOCALCONTOLLER){
    }
    else{
    }
    return 1;
}

short wyzkr688rfswhmi::ForceScopeInit(){
    if(LocalRemote == LOCALCONTOLLER){
        ui->ForceScopeView->addGraph();
        ui->ForceScopeView->graph(0)->setPen(QPen(Qt::red));
        ui->ForceScopeView->addGraph();
        ui->ForceScopeView->graph(1)->setPen(QPen(Qt::black));

        ui->ForceScopeView->graph(0)->setAntialiasedFill(true);
        ui->ForceScopeView->yAxis->setRange(-1000,10000);
        ui->ForceScopeView->xAxis->setTickLabelType(QCPAxis::ltDateTime);
        ui->ForceScopeView->xAxis->setDateTimeFormat("s");
        ui->ForceScopeView->xAxis->setAutoTickStep(false);
        ui->ForceScopeView->xAxis->setTickStep(2);
        ui->ForceScopeView->axisRect()->setupFullAxesBox();
    }
    else{
        remoteui->ForceScopeView->addGraph();
        remoteui->ForceScopeView->graph(0)->setPen(QPen(Qt::red));
        remoteui->ForceScopeView->addGraph();
        remoteui->ForceScopeView->graph(1)->setPen(QPen(Qt::black));

        remoteui->ForceScopeView->graph(0)->setAntialiasedFill(true);
        remoteui->ForceScopeView->yAxis->setRange(-1000,10000);
        remoteui->ForceScopeView->xAxis->setTickLabelType(QCPAxis::ltDateTime);
        remoteui->ForceScopeView->xAxis->setDateTimeFormat("s");
        remoteui->ForceScopeView->xAxis->setAutoTickStep(false);
        remoteui->ForceScopeView->xAxis->setTickStep(2);
        remoteui->ForceScopeView->axisRect()->setupFullAxesBox();    }
    return NOERROR;
}

short wyzkr688rfswhmi::RobotScopeInit(){
    if(LocalRemote == LOCALCONTOLLER){
        ui->J1PDataView->addGraph();
        ui->J1PDataView->graph(0)->setPen(QPen(Qt::red));
        ui->J1PDataView->graph(0)->setAntialiasedFill(true);
        ui->J1PDataView->xAxis->setTickLabelType(QCPAxis::ltDateTime);
        ui->J1PDataView->xAxis->setDateTimeFormat("s");
        ui->J1PDataView->xAxis->setAutoTickStep(false);
        ui->J1PDataView->xAxis->setTickStep(2);

        ui->J1PDataView->axisRect()->setupFullAxesBox();

        ui->J2PDataView->addGraph();
        ui->J2PDataView->graph(0)->setPen(QPen(Qt::red));
        ui->J2PDataView->graph(0)->setAntialiasedFill(true);
        ui->J2PDataView->xAxis->setTickLabelType(QCPAxis::ltDateTime);
        ui->J2PDataView->xAxis->setDateTimeFormat("s");
        ui->J2PDataView->xAxis->setAutoTickStep(false);
        ui->J2PDataView->xAxis->setTickStep(2);

        ui->J2PDataView->axisRect()->setupFullAxesBox();

        ui->J3PDataView->addGraph();
        ui->J3PDataView->graph(0)->setPen(QPen(Qt::red));
        ui->J3PDataView->graph(0)->setAntialiasedFill(true);
        ui->J3PDataView->xAxis->setTickLabelType(QCPAxis::ltDateTime);
        ui->J3PDataView->xAxis->setDateTimeFormat("s");
        ui->J3PDataView->xAxis->setAutoTickStep(false);
        ui->J3PDataView->xAxis->setTickStep(2);

        ui->J3PDataView->axisRect()->setupFullAxesBox();

        ui->J4PDataView->addGraph();
        ui->J4PDataView->graph(0)->setPen(QPen(Qt::red));
        ui->J4PDataView->graph(0)->setAntialiasedFill(true);
        ui->J4PDataView->xAxis->setTickLabelType(QCPAxis::ltDateTime);
        ui->J4PDataView->xAxis->setDateTimeFormat("s");
        ui->J4PDataView->xAxis->setAutoTickStep(false);
        ui->J4PDataView->xAxis->setTickStep(2);

        ui->J4PDataView->axisRect()->setupFullAxesBox();

        ui->J5PDataView->addGraph();
        ui->J5PDataView->graph(0)->setPen(QPen(Qt::red));
        ui->J5PDataView->graph(0)->setAntialiasedFill(true);
        ui->J5PDataView->xAxis->setTickLabelType(QCPAxis::ltDateTime);
        ui->J5PDataView->xAxis->setDateTimeFormat("s");
        ui->J5PDataView->xAxis->setAutoTickStep(false);
        ui->J5PDataView->xAxis->setTickStep(2);

        ui->J5PDataView->axisRect()->setupFullAxesBox();

        ui->J6PDataView->addGraph();
        ui->J6PDataView->graph(0)->setPen(QPen(Qt::red));
        ui->J6PDataView->graph(0)->setAntialiasedFill(true);
        ui->J6PDataView->xAxis->setTickLabelType(QCPAxis::ltDateTime);
        ui->J6PDataView->xAxis->setDateTimeFormat("s");
        ui->J6PDataView->xAxis->setAutoTickStep(false);
        ui->J6PDataView->xAxis->setTickStep(2);

        ui->J6PDataView->axisRect()->setupFullAxesBox();

        ui->J1TDataView->addGraph();
        ui->J1TDataView->graph(0)->setPen(QPen(Qt::red));
        ui->J1TDataView->graph(0)->setAntialiasedFill(true);
        ui->J1TDataView->xAxis->setTickLabelType(QCPAxis::ltDateTime);
        ui->J1TDataView->xAxis->setDateTimeFormat("s");
        ui->J1TDataView->xAxis->setAutoTickStep(false);
        ui->J1TDataView->xAxis->setTickStep(2);

        ui->J1TDataView->axisRect()->setupFullAxesBox();

        ui->J2TDataView->addGraph();
        ui->J2TDataView->graph(0)->setPen(QPen(Qt::red));
        ui->J2TDataView->graph(0)->setAntialiasedFill(true);
        ui->J2TDataView->xAxis->setTickLabelType(QCPAxis::ltDateTime);
        ui->J2TDataView->xAxis->setDateTimeFormat("s");
        ui->J2TDataView->xAxis->setAutoTickStep(false);
        ui->J2TDataView->xAxis->setTickStep(2);

        ui->J2TDataView->axisRect()->setupFullAxesBox();

        ui->J3TDataView->addGraph();
        ui->J3TDataView->graph(0)->setPen(QPen(Qt::red));
        ui->J3TDataView->graph(0)->setAntialiasedFill(true);
        ui->J3TDataView->xAxis->setTickLabelType(QCPAxis::ltDateTime);
        ui->J3TDataView->xAxis->setDateTimeFormat("s");
        ui->J3TDataView->xAxis->setAutoTickStep(false);
        ui->J3TDataView->xAxis->setTickStep(2);

        ui->J3TDataView->axisRect()->setupFullAxesBox();

        ui->J4TDataView->addGraph();
        ui->J4TDataView->graph(0)->setPen(QPen(Qt::red));
        ui->J4TDataView->graph(0)->setAntialiasedFill(true);
        ui->J4TDataView->xAxis->setTickLabelType(QCPAxis::ltDateTime);
        ui->J4TDataView->xAxis->setDateTimeFormat("s");
        ui->J4TDataView->xAxis->setAutoTickStep(false);
        ui->J4TDataView->xAxis->setTickStep(2);

        ui->J4TDataView->axisRect()->setupFullAxesBox();

        ui->J5TDataView->addGraph();
        ui->J5TDataView->graph(0)->setPen(QPen(Qt::red));
        ui->J5TDataView->graph(0)->setAntialiasedFill(true);
        ui->J5TDataView->xAxis->setTickLabelType(QCPAxis::ltDateTime);
        ui->J5TDataView->xAxis->setDateTimeFormat("s");
        ui->J5TDataView->xAxis->setAutoTickStep(false);
        ui->J5TDataView->xAxis->setTickStep(2);

        ui->J5TDataView->axisRect()->setupFullAxesBox();

        ui->J6TDataView->addGraph();
        ui->J6TDataView->graph(0)->setPen(QPen(Qt::red));
        ui->J6TDataView->graph(0)->setAntialiasedFill(true);
        ui->J6TDataView->xAxis->setTickLabelType(QCPAxis::ltDateTime);
        ui->J6TDataView->xAxis->setDateTimeFormat("s");
        ui->J6TDataView->xAxis->setAutoTickStep(false);
        ui->J6TDataView->xAxis->setTickStep(2);

        ui->J6TDataView->axisRect()->setupFullAxesBox();
    }
    else{
        remoteui->J1PDataView->addGraph();
        remoteui->J1PDataView->graph(0)->setPen(QPen(Qt::red));
        remoteui->J1PDataView->graph(0)->setAntialiasedFill(true);
        remoteui->J1PDataView->xAxis->setTickLabelType(QCPAxis::ltDateTime);
        remoteui->J1PDataView->xAxis->setDateTimeFormat("s");
        remoteui->J1PDataView->xAxis->setAutoTickStep(false);
        remoteui->J1PDataView->xAxis->setTickStep(2);

        remoteui->J1PDataView->axisRect()->setupFullAxesBox();

        remoteui->J2PDataView->addGraph();
        remoteui->J2PDataView->graph(0)->setPen(QPen(Qt::red));
        remoteui->J2PDataView->graph(0)->setAntialiasedFill(true);
        remoteui->J2PDataView->xAxis->setTickLabelType(QCPAxis::ltDateTime);
        remoteui->J2PDataView->xAxis->setDateTimeFormat("s");
        remoteui->J2PDataView->xAxis->setAutoTickStep(false);
        remoteui->J2PDataView->xAxis->setTickStep(2);

        remoteui->J2PDataView->axisRect()->setupFullAxesBox();

        remoteui->J3PDataView->addGraph();
        remoteui->J3PDataView->graph(0)->setPen(QPen(Qt::red));
        remoteui->J3PDataView->graph(0)->setAntialiasedFill(true);
        remoteui->J3PDataView->xAxis->setTickLabelType(QCPAxis::ltDateTime);
        remoteui->J3PDataView->xAxis->setDateTimeFormat("s");
        remoteui->J3PDataView->xAxis->setAutoTickStep(false);
        remoteui->J3PDataView->xAxis->setTickStep(2);

        remoteui->J3PDataView->axisRect()->setupFullAxesBox();

        remoteui->J4PDataView->addGraph();
        remoteui->J4PDataView->graph(0)->setPen(QPen(Qt::red));
        remoteui->J4PDataView->graph(0)->setAntialiasedFill(true);
        remoteui->J4PDataView->xAxis->setTickLabelType(QCPAxis::ltDateTime);
        remoteui->J4PDataView->xAxis->setDateTimeFormat("s");
        remoteui->J4PDataView->xAxis->setAutoTickStep(false);
        remoteui->J4PDataView->xAxis->setTickStep(2);

        remoteui->J4PDataView->axisRect()->setupFullAxesBox();

        remoteui->J5PDataView->addGraph();
        remoteui->J5PDataView->graph(0)->setPen(QPen(Qt::red));
        remoteui->J5PDataView->graph(0)->setAntialiasedFill(true);
        remoteui->J5PDataView->xAxis->setTickLabelType(QCPAxis::ltDateTime);
        remoteui->J5PDataView->xAxis->setDateTimeFormat("s");
        remoteui->J5PDataView->xAxis->setAutoTickStep(false);
        remoteui->J5PDataView->xAxis->setTickStep(2);

        remoteui->J5PDataView->axisRect()->setupFullAxesBox();

        remoteui->J6PDataView->addGraph();
        remoteui->J6PDataView->graph(0)->setPen(QPen(Qt::red));
        remoteui->J6PDataView->graph(0)->setAntialiasedFill(true);
        remoteui->J6PDataView->xAxis->setTickLabelType(QCPAxis::ltDateTime);
        remoteui->J6PDataView->xAxis->setDateTimeFormat("s");
        remoteui->J6PDataView->xAxis->setAutoTickStep(false);
        remoteui->J6PDataView->xAxis->setTickStep(2);

        remoteui->J6PDataView->axisRect()->setupFullAxesBox();

        remoteui->J1TDataView->addGraph();
        remoteui->J1TDataView->graph(0)->setPen(QPen(Qt::red));
        remoteui->J1TDataView->graph(0)->setAntialiasedFill(true);
        remoteui->J1TDataView->xAxis->setTickLabelType(QCPAxis::ltDateTime);
        remoteui->J1TDataView->xAxis->setDateTimeFormat("s");
        remoteui->J1TDataView->xAxis->setAutoTickStep(false);
        remoteui->J1TDataView->xAxis->setTickStep(2);

        remoteui->J1TDataView->axisRect()->setupFullAxesBox();

        remoteui->J2TDataView->addGraph();
        remoteui->J2TDataView->graph(0)->setPen(QPen(Qt::red));
        remoteui->J2TDataView->graph(0)->setAntialiasedFill(true);
        remoteui->J2TDataView->xAxis->setTickLabelType(QCPAxis::ltDateTime);
        remoteui->J2TDataView->xAxis->setDateTimeFormat("s");
        remoteui->J2TDataView->xAxis->setAutoTickStep(false);
        remoteui->J2TDataView->xAxis->setTickStep(2);

        remoteui->J2TDataView->axisRect()->setupFullAxesBox();

        remoteui->J3TDataView->addGraph();
        remoteui->J3TDataView->graph(0)->setPen(QPen(Qt::red));
        remoteui->J3TDataView->graph(0)->setAntialiasedFill(true);
        remoteui->J3TDataView->xAxis->setTickLabelType(QCPAxis::ltDateTime);
        remoteui->J3TDataView->xAxis->setDateTimeFormat("s");
        remoteui->J3TDataView->xAxis->setAutoTickStep(false);
        remoteui->J3TDataView->xAxis->setTickStep(2);

        remoteui->J3TDataView->axisRect()->setupFullAxesBox();

        remoteui->J4TDataView->addGraph();
        remoteui->J4TDataView->graph(0)->setPen(QPen(Qt::red));
        remoteui->J4TDataView->graph(0)->setAntialiasedFill(true);
        remoteui->J4TDataView->xAxis->setTickLabelType(QCPAxis::ltDateTime);
        remoteui->J4TDataView->xAxis->setDateTimeFormat("s");
        remoteui->J4TDataView->xAxis->setAutoTickStep(false);
        remoteui->J4TDataView->xAxis->setTickStep(2);

        remoteui->J4TDataView->axisRect()->setupFullAxesBox();

        remoteui->J5TDataView->addGraph();
        remoteui->J5TDataView->graph(0)->setPen(QPen(Qt::red));
        remoteui->J5TDataView->graph(0)->setAntialiasedFill(true);
        remoteui->J5TDataView->xAxis->setTickLabelType(QCPAxis::ltDateTime);
        remoteui->J5TDataView->xAxis->setDateTimeFormat("s");
        remoteui->J5TDataView->xAxis->setAutoTickStep(false);
        remoteui->J5TDataView->xAxis->setTickStep(2);

        remoteui->J5TDataView->axisRect()->setupFullAxesBox();

        remoteui->J6TDataView->addGraph();
        remoteui->J6TDataView->graph(0)->setPen(QPen(Qt::red));
        remoteui->J6TDataView->graph(0)->setAntialiasedFill(true);
        remoteui->J6TDataView->xAxis->setTickLabelType(QCPAxis::ltDateTime);
        remoteui->J6TDataView->xAxis->setDateTimeFormat("s");
        remoteui->J6TDataView->xAxis->setAutoTickStep(false);
        remoteui->J6TDataView->xAxis->setTickStep(2);

        remoteui->J6TDataView->axisRect()->setupFullAxesBox();
    }
    return NOERROR;
}

short wyzkr688rfswhmi::ForceScopeUpdate(){
    if(this->LocalRemote == LOCALCONTOLLER){
        double key;
        double PinPos;
        static double lastPointKey1 = 0;

        if(this->pbackendinterface != nullptr){
            this->pbackendinterface->ReadForceControlForceRealValue(mTechData.ForceSensorReal);
            this->pbackendinterface->ReadForceControlForceSetValue(mTechData.ForceProcessSet);

            if(mTechData.ForceSensorReal<=0){
                PinPos = 0;
            }
            else{
                PinPos = 3*(mTechData.ForceSensorReal/mTechData.ForceProcessSet);
            }
        }
        key = QDateTime::currentDateTime().toMSecsSinceEpoch()/1000.0;
        if (key-lastPointKey1 > 0.01){
            ui->ForceScopeView->graph(0)->addData(key, mTechData.ForceSensorReal);
            ui->ForceScopeView->graph(0)->removeDataBefore(key-20);
            ui->ForceScopeView->graph(1)->addData(key, mTechData.ForceProcessSet);
            ui->ForceScopeView->graph(1)->removeDataBefore(key-20);
            lastPointKey1 = key;
        }

        this->ui->ForceScopeView->xAxis->setRange(key+0.25, 20, Qt::AlignRight);
        this->ui->ForceScopeView->replot();
        this->ui->PinView->RSFWTooLPinViewUpdate(PinPos);

    }
    else{
        double key;
        double PinPos;
        static double remotelastPointKey1 = 0;

        if(mTechData.ForceSensorReal<=0){
            PinPos = 0;
        }
        else{
            PinPos = 3*(mTechData.ForceSensorReal/mTechData.ForceProcessSet);
        }
        key = QDateTime::currentDateTime().toMSecsSinceEpoch()/1000.0;
        if (key-remotelastPointKey1 > 0.01){
            remoteui->ForceScopeView->graph(0)->addData(key, mTechData.ForceSensorReal);
            remoteui->ForceScopeView->graph(0)->removeDataBefore(key-20);
            remoteui->ForceScopeView->graph(1)->addData(key, mTechData.ForceProcessSet);
            remoteui->ForceScopeView->graph(1)->removeDataBefore(key-20);
            remotelastPointKey1 = key;
        }

        this->remoteui->ForceScopeView->xAxis->setRange(key+0.25, 20, Qt::AlignRight);
        this->remoteui->ForceScopeView->replot();
        this->remoteui->PinView->RSFWTooLPinViewUpdate(PinPos);
    }
    return 1;
}

short wyzkr688rfswhmi::RobotScopeUpdate(){
    double Joint[6];
    if(this->LocalRemote == LOCALCONTOLLER){
        if(this->pbackendinterface != nullptr){
            pbackendinterface->ReadRobotJointData(mRobot.RobotJointData);
            pbackendinterface->ReadRobotJointTorData(mRobot.RobotJointTorData);
        }
        Joint[0] =  this->mRobot.RobotJointData[0];
        Joint[1] =  this->mRobot.RobotJointData[1];
        Joint[2] =  this->mRobot.RobotJointData[2];
        Joint[3] =  this->mRobot.RobotJointData[3];
        Joint[4] =  this->mRobot.RobotJointData[4];
        Joint[5] =  this->mRobot.RobotJointData[5];
        this->ui->RobotView->RoboticOpenViewUpdate(Joint);
        double key = QDateTime::currentDateTime().toMSecsSinceEpoch()/1000.0;
        static double lastPointKey2 = 0;
        if (key-lastPointKey2 > 0.01){
            ui->J1PDataView->graph(0)->addData(key, mRobot.RobotJointData[0]);
            ui->J1PDataView->graph(0)->removeDataBefore(key-20);
            ui->J2PDataView->graph(0)->addData(key, mRobot.RobotJointData[1]);
            ui->J2PDataView->graph(0)->removeDataBefore(key-20);
            ui->J3PDataView->graph(0)->addData(key, mRobot.RobotJointData[2]);
            ui->J3PDataView->graph(0)->removeDataBefore(key-20);
            ui->J4PDataView->graph(0)->addData(key, mRobot.RobotJointData[3]);
            ui->J4PDataView->graph(0)->removeDataBefore(key-20);
            ui->J5PDataView->graph(0)->addData(key, mRobot.RobotJointData[4]);
            ui->J5PDataView->graph(0)->removeDataBefore(key-20);
            ui->J6PDataView->graph(0)->addData(key, mRobot.RobotJointData[5]);
            ui->J6PDataView->graph(0)->removeDataBefore(key-20);
            ui->J1TDataView->graph(0)->addData(key, mRobot.RobotJointTorData[0]);
            ui->J1TDataView->graph(0)->removeDataBefore(key-20);
            ui->J2TDataView->graph(0)->addData(key, mRobot.RobotJointTorData[1]);
            ui->J2TDataView->graph(0)->removeDataBefore(key-20);
            ui->J3TDataView->graph(0)->addData(key, mRobot.RobotJointTorData[2]);
            ui->J3TDataView->graph(0)->removeDataBefore(key-20);
            ui->J4TDataView->graph(0)->addData(key, mRobot.RobotJointTorData[3]);
            ui->J4TDataView->graph(0)->removeDataBefore(key-20);
            ui->J5TDataView->graph(0)->addData(key, mRobot.RobotJointTorData[4]);
            ui->J5TDataView->graph(0)->removeDataBefore(key-20);
            ui->J6TDataView->graph(0)->addData(key, mRobot.RobotJointTorData[5]);
            ui->J6TDataView->graph(0)->removeDataBefore(key-20);
            ui->J1PDataView->yAxis->rescale();
            ui->J2PDataView->yAxis->rescale();
            ui->J3PDataView->yAxis->rescale();
            ui->J4PDataView->yAxis->rescale();
            ui->J5PDataView->yAxis->rescale();
            ui->J6PDataView->yAxis->rescale();
            ui->J1TDataView->yAxis->rescale();
            ui->J2TDataView->yAxis->rescale();
            ui->J3TDataView->yAxis->rescale();
            ui->J4TDataView->yAxis->rescale();
            ui->J5TDataView->yAxis->rescale();
            ui->J6TDataView->yAxis->rescale();
            lastPointKey2 = key;
        }
        ui->J1PDataView->xAxis->setRange(key+0.25, 20, Qt::AlignRight);
        ui->J1PDataView->replot();
        ui->J2PDataView->xAxis->setRange(key+0.25, 20, Qt::AlignRight);
        ui->J2PDataView->replot();
        ui->J3PDataView->xAxis->setRange(key+0.25, 20, Qt::AlignRight);
        ui->J3PDataView->replot();
        ui->J4PDataView->xAxis->setRange(key+0.25, 20, Qt::AlignRight);
        ui->J4PDataView->replot();
        ui->J5PDataView->xAxis->setRange(key+0.25, 20, Qt::AlignRight);
        ui->J5PDataView->replot();
        ui->J6PDataView->xAxis->setRange(key+0.25, 20, Qt::AlignRight);
        ui->J6PDataView->replot();
        ui->J1TDataView->xAxis->setRange(key+0.25, 20, Qt::AlignRight);
        ui->J1TDataView->replot();
        ui->J2TDataView->xAxis->setRange(key+0.25, 20, Qt::AlignRight);
        ui->J2TDataView->replot();
        ui->J3TDataView->xAxis->setRange(key+0.25, 20, Qt::AlignRight);
        ui->J3TDataView->replot();
        ui->J4TDataView->xAxis->setRange(key+0.25, 20, Qt::AlignRight);
        ui->J4TDataView->replot();
        ui->J5TDataView->xAxis->setRange(key+0.25, 20, Qt::AlignRight);
        ui->J5TDataView->replot();
        ui->J6TDataView->xAxis->setRange(key+0.25, 20, Qt::AlignRight);
        ui->J6TDataView->replot();
    }
    else{
            Joint[0] =  this->mRobot.RobotJointData[0];
            Joint[1] =  this->mRobot.RobotJointData[1];
            Joint[2] =  this->mRobot.RobotJointData[2];
            Joint[3] =  this->mRobot.RobotJointData[3];
            Joint[4] =  this->mRobot.RobotJointData[4];
            Joint[5] =  this->mRobot.RobotJointData[5];
            this->remoteui->RobotView->RoboticOpenViewUpdate(Joint);
            double key = QDateTime::currentDateTime().toMSecsSinceEpoch()/1000.0;
            static double remotelastPointKey2 = 0;
            if (key-remotelastPointKey2 > 0.01){
                remoteui->J1PDataView->graph(0)->addData(key, mRobot.RobotJointData[0]);
                remoteui->J1PDataView->graph(0)->removeDataBefore(key-20);
                remoteui->J2PDataView->graph(0)->addData(key, mRobot.RobotJointData[1]);
                remoteui->J2PDataView->graph(0)->removeDataBefore(key-20);
                remoteui->J3PDataView->graph(0)->addData(key, mRobot.RobotJointData[2]);
                remoteui->J3PDataView->graph(0)->removeDataBefore(key-20);
                remoteui->J4PDataView->graph(0)->addData(key, mRobot.RobotJointData[3]);
                remoteui->J4PDataView->graph(0)->removeDataBefore(key-20);
                remoteui->J5PDataView->graph(0)->addData(key, mRobot.RobotJointData[4]);
                remoteui->J5PDataView->graph(0)->removeDataBefore(key-20);
                remoteui->J6PDataView->graph(0)->addData(key, mRobot.RobotJointData[5]);
                remoteui->J6PDataView->graph(0)->removeDataBefore(key-20);
                remoteui->J1TDataView->graph(0)->addData(key, mRobot.RobotJointTorData[0]);
                remoteui->J1TDataView->graph(0)->removeDataBefore(key-20);
                remoteui->J2TDataView->graph(0)->addData(key, mRobot.RobotJointTorData[1]);
                remoteui->J2TDataView->graph(0)->removeDataBefore(key-20);
                remoteui->J3TDataView->graph(0)->addData(key, mRobot.RobotJointTorData[2]);
                remoteui->J3TDataView->graph(0)->removeDataBefore(key-20);
                remoteui->J4TDataView->graph(0)->addData(key, mRobot.RobotJointTorData[3]);
                remoteui->J4TDataView->graph(0)->removeDataBefore(key-20);
                remoteui->J5TDataView->graph(0)->addData(key, mRobot.RobotJointTorData[4]);
                remoteui->J5TDataView->graph(0)->removeDataBefore(key-20);
                remoteui->J6TDataView->graph(0)->addData(key, mRobot.RobotJointTorData[5]);
                remoteui->J6TDataView->graph(0)->removeDataBefore(key-20);
                remoteui->J1PDataView->yAxis->rescale();
                remoteui->J2PDataView->yAxis->rescale();
                remoteui->J3PDataView->yAxis->rescale();
                remoteui->J4PDataView->yAxis->rescale();
                remoteui->J5PDataView->yAxis->rescale();
                remoteui->J6PDataView->yAxis->rescale();
                remoteui->J1TDataView->yAxis->rescale();
                remoteui->J2TDataView->yAxis->rescale();
                remoteui->J3TDataView->yAxis->rescale();
                remoteui->J4TDataView->yAxis->rescale();
                remoteui->J5TDataView->yAxis->rescale();
                remoteui->J6TDataView->yAxis->rescale();
                remotelastPointKey2 = key;
            }
            remoteui->J1PDataView->xAxis->setRange(key+0.25, 20, Qt::AlignRight);
            remoteui->J1PDataView->replot();
            remoteui->J2PDataView->xAxis->setRange(key+0.25, 20, Qt::AlignRight);
            remoteui->J2PDataView->replot();
            remoteui->J3PDataView->xAxis->setRange(key+0.25, 20, Qt::AlignRight);
            remoteui->J3PDataView->replot();
            remoteui->J4PDataView->xAxis->setRange(key+0.25, 20, Qt::AlignRight);
            remoteui->J4PDataView->replot();
            remoteui->J5PDataView->xAxis->setRange(key+0.25, 20, Qt::AlignRight);
            remoteui->J5PDataView->replot();
            remoteui->J6PDataView->xAxis->setRange(key+0.25, 20, Qt::AlignRight);
            remoteui->J6PDataView->replot();
            remoteui->J1TDataView->xAxis->setRange(key+0.25, 20, Qt::AlignRight);
            remoteui->J1TDataView->replot();
            remoteui->J2TDataView->xAxis->setRange(key+0.25, 20, Qt::AlignRight);
            remoteui->J2TDataView->replot();
            remoteui->J3TDataView->xAxis->setRange(key+0.25, 20, Qt::AlignRight);
            remoteui->J3TDataView->replot();
            remoteui->J4TDataView->xAxis->setRange(key+0.25, 20, Qt::AlignRight);
            remoteui->J4TDataView->replot();
            remoteui->J5TDataView->xAxis->setRange(key+0.25, 20, Qt::AlignRight);
            remoteui->J5TDataView->replot();
            remoteui->J6TDataView->xAxis->setRange(key+0.25, 20, Qt::AlignRight);
            remoteui->J6TDataView->replot();
    }
    return 1;
}

void wyzkr688rfswhmi::RemoteDataRecv(QByteArray Data){
    double tempRecvValue[8];
    if(this->LocalRemote == LOCALCONTOLLER){
    }
    else{
        int loopi = 0;
        QXmlStreamReader mQXmlStreamReader;
        mQXmlStreamReader.addData(Data);
        while(!mQXmlStreamReader.atEnd()){
            if(mQXmlStreamReader.isStartElement()){
                if(mQXmlStreamReader.name() == "AIst"){
                    loopi = 0;
                    foreach (const QXmlStreamAttribute & attribute, mQXmlStreamReader.attributes()){
                        QStringRef tempStringRef;
                        QString  tempQString;
                        tempStringRef = attribute.value();
                        tempQString = tempStringRef.toString();
                        mRobot.RobotJointData[loopi] = tempQString.toDouble();
                        loopi++;
                    }
                }
                else if(mQXmlStreamReader.name() == "ATIst"){
                    loopi = 0;
                    foreach (const QXmlStreamAttribute & attribute, mQXmlStreamReader.attributes()){
                        QStringRef tempStringRef;
                        QString  tempQString;
                        tempStringRef = attribute.value();
                        tempQString = tempStringRef.toString();
                        mRobot.RobotJointTorData[loopi]= tempQString.toDouble();
                        loopi++;
                    }
                }
                else if(mQXmlStreamReader.name() == "TechInfo"){
                    loopi = 0;
                    foreach (const QXmlStreamAttribute & attribute, mQXmlStreamReader.attributes()){
                        QStringRef tempStringRef;
                        QString  tempQString;
                        tempStringRef = attribute.value();
                        tempQString = tempStringRef.toString();
                        tempRecvValue[loopi] = tempQString.toDouble();
                        loopi++;
                    }
                    this->mTechData.RFSWStage = tempRecvValue[0];
                    this->mTechData.SpindleSpeedReal = tempRecvValue[1];
                    this->mTechData.ForceInitPosSet = tempRecvValue[2];
                    this->mTechData.InitPosDelayTime = tempRecvValue[3];
                    this->mTechData.ForceProcessSet = tempRecvValue[4];
                    this->mTechData.ForceAdjGlobalCoefficient = tempRecvValue[5];
                    this->mTechData.ForceSensorReal = tempRecvValue[6];
                    qDebug()<<tempRecvValue[1]<<endl;
                }
            }
            mQXmlStreamReader.readNext();
        }

        mQXmlStreamReader.clear();
    }
}
void wyzkr688rfswhmi::RemoteDataSend(QByteArray& Data){
    if(this->LocalRemote == LOCALCONTOLLER){
        char tempSend[64];
        QString SendString;
        QXmlStreamWriter stream(&SendString);

        memset(tempSend,'\0',strlen(tempSend));
        stream.writeStartElement("TecController");
            stream.writeAttribute("Tec","NormalPlugin");

            stream.writeEmptyElement("AIst");
                sprintf(tempSend,"%f", mRobot.RobotJointData[0]);
                    stream.writeAttribute("A1",tempSend);
                sprintf(tempSend,"%f", mRobot.RobotJointData[1]);
                    stream.writeAttribute("A2",tempSend);
                sprintf(tempSend,"%f", mRobot.RobotJointData[2]);
                    stream.writeAttribute("A3",tempSend);
                sprintf(tempSend,"%f", mRobot.RobotJointData[3]);
                    stream.writeAttribute("A4",tempSend);
                sprintf(tempSend,"%f", mRobot.RobotJointData[4]);
                    stream.writeAttribute("A5",tempSend);
                sprintf(tempSend,"%f", mRobot.RobotJointData[5]);
                    stream.writeAttribute("A6",tempSend);

            stream.writeEmptyElement("ATIst");
                sprintf(tempSend,"%f", mRobot.RobotJointTorData[0]);
                    stream.writeAttribute("A1T",tempSend);
                sprintf(tempSend,"%f", mRobot.RobotJointTorData[1]);
                    stream.writeAttribute("A2T",tempSend);
                sprintf(tempSend,"%f", mRobot.RobotJointTorData[2]);
                    stream.writeAttribute("A3T",tempSend);
                sprintf(tempSend,"%f", mRobot.RobotJointTorData[3]);
                    stream.writeAttribute("A4T",tempSend);
                sprintf(tempSend,"%f", mRobot.RobotJointTorData[4]);
                    stream.writeAttribute("A5T",tempSend);
                sprintf(tempSend,"%f", mRobot.RobotJointTorData[5]);
                    stream.writeAttribute("A6T",tempSend);

            stream.writeEmptyElement("TechInfo");
                sprintf(tempSend,"%d", mTechData.RFSWStage);
                    stream.writeAttribute("RFSWStage",tempSend);
                sprintf(tempSend,"%.1f", mTechData.SpindleSpeedReal);
                    stream.writeAttribute("Spindle",tempSend);
                sprintf(tempSend,"%.1f", mTechData.ForceInitPosSet);
                    stream.writeAttribute("FzInitSet",tempSend);
                sprintf(tempSend,"%d", mTechData.InitPosDelayTime);
                    stream.writeAttribute("FzDelayTime",tempSend);
                sprintf(tempSend,"%.1f", mTechData.ForceProcessSet);
                    stream.writeAttribute("FzSet",tempSend);
                sprintf(tempSend,"%.3f", mTechData.ForceAdjGlobalCoefficient);
                    stream.writeAttribute("FzCoefficient",tempSend);
                sprintf(tempSend,"%.1f", mTechData.ForceSensorReal);
                    stream.writeAttribute("FzReal",tempSend);

        stream.writeEndElement();
        Data = SendString.toLocal8Bit();
    }
    else{
        QString SendString;
        QXmlStreamWriter stream(&SendString);
        stream.writeStartElement("TecController");
            stream.writeAttribute("Tec","NormalPlugin");

            stream.writeEndElement();
        Data = SendString.toLocal8Bit();
    }
}

short wyzkr688rfswhmi::ForceScopeRelease(){
    if(this->LocalRemote == LOCALCONTOLLER){
    }
    else{
    }
    return 1;
}
short wyzkr688rfswhmi::RobotScopeRelease(){
    if(this->LocalRemote == LOCALCONTOLLER){
    }
    else{
    }
    return 1;
}
